<div class="main-content">
	<div class="breadcrumbs" id="breadcrumbs">
		<script type="text/javascript">
			try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
		</script>

		<ul class="breadcrumb">
			<li>
				<i class="icon-home home-icon"></i>
				<a href="#">系统首页</a>
			</li>
			<li class="active">
				信息互动
			</li>
            <li class="active">
				活动资讯
			</li>
		</ul><!-- .breadcrumb -->
	</div>
	<!-- Main content -->
    <div class="page-content">
    	<div class="row">
    	    <div class="page-header">
    			<h1>活动资讯信息表</h1>
    		</div>
    		<div class="col-xs-12">
    		
            	<a class="btn btn-info btn-sm" href="<?php echo base_url()."admin/message/add_message_news"?>"><i class="icon-copy"></i>新增</a>
            
                <a href="javascript:void(0)" onclick="delSomeModal()" data-toggle="modal" class="btn btn-danger btn-sm"><i class="icon-trash"></i>删除</a>
            
            </div>
            <div class="col-md-12 col-sm-12 col-xs-12 form">
                <div class="row">
                <form action="<?php echo base_url().'admin/message/query_message_news'?>" method="get">
                	<div class="wh">
                    	<label>标题：</label>
                        <input type="text"  name="title" value="<?php if (isset($title))echo $title;?>"/>
                    </div>
					<div class="wh">
                    	<label>发布人：</label>
                        <input type="text"  name="admin_name" value="<?php if (isset($admin_name))echo $admin_name;?>"/>
                    </div>
                    <div class="wh">
						<button class="btn btn-sm btn-info" type="submit"><i class="icon-search"></i>查询</button>
                    </div>
                </form>
                </div>
			</div>
			<div class="col-xs-12 margin_t margin_b">
				<div class="table-responsive  tab">
				<form action="<?php echo base_url()."admin/message/del_some_message_news"?>" method="post" id="delForm">
					<table id="sample-table-1" class="table table-striped table-bordered table-hover">
						<thead>
							<tr>
								<th class="center" style="width: 3%;">
									<label>
										<input type="checkbox" class="ace" />
										<span class="lbl"></span>
									</label>
								</th>
								<th>标题</th>
                                <th>发布人</th>
                                <th>发布时间</th>
                                <th style="width: 25%;">操作</th>
							</tr>
						</thead>
						<tbody>
						<?php if (isset($result)&&count($result)>0){
                            	foreach ($result as $news){
                            	?>
							<tr>
								<td class="center">
                                	<p>
									<label>
										<input type="checkbox" class="ace" name="num[]" value="<?php echo $news->id;?>"/>
										<span class="lbl"></span>
									</label>
                                    </p>
								</td>
								<td><p><?php echo $news->title;?></p></td>
								<td><p><?php echo $news->user_name;?></p></td>
								<td><p><?php echo $news->create_time;?></p></td>
								<td><p>
								
								    <a class="btn btn-sm btn-info" href="<?php echo base_url().'admin/message/edit_message_news/'.$news->id;?>"><i class="icon-edit"></i>编辑</a>
                                    <a href="javascript:void(0)" onclick="delmodal('<?php echo $news->id;?>')" data-toggle="modal" class="btn btn-danger btn-sm"><i class="icon-trash"></i>删除</a>
                                    <a href="javascript:void(0)" onclick="sendSomeModal('<?php echo $news->id;?>')" data-toggle="modal" class="btn btn-info btn-sm"><i class="icon-share-alt"></i>推送到APP</a>
                                    </p>
                                </td>
                                </tr>
    						<?php }
                            }else{?>
                            <tr>
                            	<td colspan="5">无数据</td>
                            </tr>
                            <?php }?>
                            </tbody>
                         </table>
                     </form>
                     </div><!-- /.table-responsive -->
	            </div>
	            <div class="col-sm-12">
                	<div class="modal-footer no-margin-top">
	                	<div class="pull-left record">
							共<?php echo $count;?>条记录
	                    </div>
                		<?php if (isset($page))echo $page;?>
                	</div>
                </div>
            </div><!-- /.row -->
		</div><!-- /.page-content -->
	</div><!-- /.main-content -->
	<div id="delModal" class="modal fade" role="dialog" aria-hidden="true">
		<div class="modal-dialog" style="width: 300px">
			<div class="modal-content">
				<div class="modal-header">
				  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				  <h3>提示信息</h3>
				</div>
				<div class="modal-body">
				  <p>确定要删除该资讯吗？</p>
				</div>
				<div class="modal-footer">
				  <a id="delbtn" href="#" class="btn btn-danger">确定</a>
				  <a href="#" class="btn btn-info" data-dismiss="modal" aria-hidden="true">取消</a>
				</div>
			</div>
		</div>
	</div>
	
	<div id="delsomeModal" class="modal fade" role="dialog" aria-hidden="true">
		<div class="modal-dialog" style="width: 300px">
			<div class="modal-content">
				<div class="modal-header">
				  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				  <h3>提示信息</h3>
				</div>
				<div class="modal-body">
				  <p>确定要删除所选资讯吗？</p>
				</div>
				<div class="modal-footer">
				  <button id="delsomebtn" type="submit" class="btn btn-danger">确定</button>
				  <a href="#" class="btn btn-info" data-dismiss="modal" aria-hidden="true">取消</a>
				</div>
			</div>
		</div>
	</div>
	<div id="sendsomeModal" class="modal fade" role="dialog" aria-hidden="true">
	<div class="modal-dialog" style="width: 300px">
		<div class="modal-content">
			<div class="modal-header">
			  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
			  <h3>提示信息</h3>
			</div>
			<div class="modal-body">
			  <p>确定要推送所选健康资讯吗？</p>
			</div>
			<div class="modal-footer">
			  <button id="sendsomebtn" type="submit" class="btn btn-danger">确定</button>
			  <a href="#" class="btn btn-info" data-dismiss="modal" aria-hidden="true">取消</a>
			</div>
		</div>
	</div>
</div>
<div id="send_modal" class="modal fade" role="dialog" aria-hidden="true">
	<div class="modal-dialog" style="width: 450px;height: 100%;">
		<div class="modal-content">
			<div class="modal-header">
			  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
			  <h3>请选择要推送的用户标签</h3>
			</div>
			
			<input type="hidden" name="id" value="" id="news_id">
			
			<div class="modal-body" style="height: 80%;">
				<table class="table table-striped table-bordered" id="send_table">
                    <thead>
                        <tr>
                        	<th class="center" style="width: 5%">
                            	<label>
    								<input type="checkbox" class="ace" />
    								<span class="lbl"></span>
    							</label>
                        	</th>
                        	<th>标签名称</th>
                    	</tr>
                    </thead>
                    <tbody>
                    <?php if (isset($tag)&&count($tag)>0){
                    foreach ($tag as $val){?>
                        <tr>
                        	<td class="center">
                        		<label>
    								<input type="checkbox" class="ace" name="send_tag[]" value="<?php echo $val->value;?>" id="num"/>
    								<span class="lbl"></span>
    							</label>
                        	</td>
                        	<td><?php echo $val->name;?></td>
                    	</tr>
                    <?php }
                    }?>
                	</tbody>
            	</table>
            	<p><font color="red"> *注：若不选择则默认推送给全部用户。</font></p>
			</div>
			
			<div class="modal-footer">
				<button type="button" class="btn btn-info" id="send_btn">推送</button>
				<a href="#" class="btn btn-danger" data-dismiss="modal" aria-hidden="true">取消</a>
			</div>
		</div>
	</div>
</div>
	<script type="text/javascript">
	function delmodal(id){
		$("#delbtn").attr('href','<?php echo base_url().'admin/message/del_message_news/'?>'+id);
	    $('#delModal').modal('show');
	}
	function delSomeModal(){
		if(checkSelect()){
	    	$('#delsomeModal').modal('show');
		}else{
			alert('请选择正确的记录进行删除');
		}
	}
	$("#delsomebtn").click(function(){
		$("#delForm").submit();
    });
	function sendSomeModal(id){
		
		$('#news_id').val(id);
		$('#send_modal').modal('show');
	}
	$("#send_btn").click(function(){
		$('#send_modal').modal('hide');
		 showLoading('推送中');
		 var tag_arr = [];
		 $('#send_table').find('tr > td:first-child input:checkbox').each(function(){
			 if(this.checked){
				tag_arr.push(this.value);
			 } 
		});
		 $.ajax( {
	        url:'<?php echo site_url("admin/message/send_some_message_news")?>',
	        data:{send_tag:tag_arr,id:$('#news_id').val()},
	        type:'post',
	        cache:false,
	        dataType:'json',    
	        success:function(data) {
	        	hideLoading();
	        	alert('已推送'+data.count+'条');
	        },
	        error : function() {  
	        	hideLoading();     
				alert("error");    
	        }
		 });
	});
	</script>